package behaviorpattern.iterator;

public class ConcreteIterator extends Iterator{
	private ConcreteAggregate aggregate;
	private int index;
	
	public ConcreteIterator(ConcreteAggregate aggregate) {
		this.aggregate = aggregate;
		index = 0;
	}
	
	@Override
	public Object first() {
		return aggregate.getItem(0);
	}

	@Override
	public Object next() {
		Object ret = null;
		
		if(index < aggregate.getItemsLength() - 1) {
			index ++;
			ret = aggregate.getItem(index);
		}
		
		return ret;
	}

	@Override
	public boolean isDone() {
		return index >= aggregate.getItemsLength() - 1 ? true: false;
	}

	@Override
	public Object currentItem() {
		return aggregate.getItem(index);
	}
}
